package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.CornerPathEffect
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* DeleteItemView01
* */
class DeleteItemView01 @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mStrokeWidth0 = context.resources.getDimension(R.dimen.dp_2)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeWidth = mStrokeWidth0
            strokeCap = Paint.Cap.SQUARE
            strokeJoin = Paint.Join.ROUND
            style = Paint.Style.STROKE
            pathEffect = CornerPathEffect(context.resources.getDimension(R.dimen.dp_5))
            color = context.resources.getColor(R.color.color_B9EA09)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeWidth = mStrokeWidth0
            strokeCap = Paint.Cap.SQUARE
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_DB39F6)
        }
    }

    private val mPath0 by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)

            save()
            translate(0F,-cy / 2)
            drawLine(
                -cx * 4 / 5,
                0F,
                -cx / 5,
                0F,
                mPaint0
            )

            drawArc(
                -cx / 5,
                -cy / 5,
                cx / 5,
                cy / 5,
                180F,
                180F,
                false,
                mPaint0
            )

            drawLine(
                cx / 5,
                0F,
                cx * 4 / 5,
                0F,
                mPaint0
            )
            restore()

            mPath0.apply {
                mPath0.reset()
                moveTo(-cx * 17 / 25, -cy * 14 / 40)
                lineTo(-cx * 15 / 25, cy - (cy / 2 - cy / 5))
                lineTo(cx * 15 / 25, cy - (cy / 2 - cy / 5))
                lineTo(cx * 17 / 25, -cy * 14 / 40)
            }
            drawPath(mPath0, mPaint0)

            mPath0.apply {
                reset()
                moveTo(-cx / 5, 0F)
                lineTo(-cx / 5, cy * 2 / 5)
            }
            drawPath(mPath0, mPaint1)

            mPath0.apply {
                reset()
                moveTo(cx / 5, 0F)
                lineTo(cx / 5, cy * 2 / 5)
            }
            drawPath(mPath0, mPaint1)
        }
    }
}